import 'package:cbec_app/components/base/base_ctr.dart';
import 'package:cbec_app/components/http/network.dart';
import 'package:cbec_app/pages/goods/entity/book_info_item_detail_entity.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:umeng_common_sdk/umeng_common_sdk.dart';

class GroupBuyingItemDetailCtr extends BaseController {
  BookInfoItemDetailEntity? bookInfo;

  @override
  void onInit() {
    super.onInit();
    var orderId = Get.arguments;
    print('orderId is  $orderId');
    if (orderId != null) {
      getGroupDetail(orderId);
    }

    UmengCommonSdk.onPageStart('评团详情');
  }

  @override
  void onClose() {
    super.onClose();
    UmengCommonSdk.onPageEnd('评团详情');
  }

  //获取拼团详情
  void getGroupDetail(String orderId) {
    Tools.showLoading();
    Network.getGroupDetail(orderId).then((value) {
      bookInfo = BookInfoItemDetailEntity.fromJson(value);
      print('获取拼团详情 ${bookInfo}');
      update();
      Tools.hideLoading();
    }).catchError((error) {
      Tools.hideLoading();
    });
  }

  ///复制单号
  void copy(String text) async {
    await Clipboard.setData(ClipboardData(text: text));
    Tools.showToast("订单号已复制");
  }
}
